package com.asset.dispoal.business.repayment.service.command;

import com.asset.dispoal.business.casedispose.dto.CaseDisposePageResponse;
import com.asset.dispoal.business.repayment.domain.db.mapper.RepaymentMapper;
import com.asset.dispoal.business.repayment.dto.RepaymentRequest;
import com.asset.dispoal.commom.page.PagingQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

/**
 * @description:
 * @author: yf
 * @date: 2022-09-26 14:47:13
 */
@Repository
public class QueryRepaymentListCommand implements BaseCommand<RepaymentRequest, Result<PageVO<CaseDisposePageResponse>>> {
    @Autowired
    private RepaymentMapper repaymentMapper;

    @Override
    public Result<PageVO<CaseDisposePageResponse>> execute(RepaymentRequest repaymentRequest) {
        Integer count = repaymentMapper.count(repaymentRequest);
        Page<RepaymentRequest> page = PagingQuery.getPage(count, repaymentRequest);
        PageVO<CaseDisposePageResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            pageVO.setResult(repaymentMapper.queryPage(page));
        }
        return Result.ok(pageVO);
    }
}
